//
//  YLSignHomePageViewController.m
//  TheTenthAnniversaryOfMobileUnion
//
//  Created by kuangbiao on 2019/1/24.
//  Copyright © 2019 kuangbiao. All rights reserved.
//

#import "YLSignHomePageViewController.h"
#import "YLSettingViewController.h"
#import "YLFaceIdentifyViewController.h"
#import "YLSignFirstModel.h"

@interface YLSignHomePageViewController ()
//实到人数
@property (weak, nonatomic) IBOutlet UILabel *attendanceLabel;
//应到人数
@property (weak, nonatomic) IBOutlet UILabel *SupposedComeLabel;

@end

@implementation YLSignHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
}

- (void)initView{
    self.hiddenLogo = YES;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self requestWithMeetingNo];
    //隐藏返回按钮
    self.navigationItem.hidesBackButton = YES;
    //禁止页面左侧滑动返回，注意，如果仅仅需要禁止此单个页面返回，还需要在viewWillDisapper下开放侧滑权限
    // 禁用返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    // 开启返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

#pragma mark - 设置按钮点击事件
- (IBAction)setBtnClickAction:(id)sender {
    YLSettingViewController *setVC = [[YLSettingViewController alloc] initWithNibName:@"YLSettingViewController" bundle:nil];
    [self.navigationController pushViewController:setVC animated:YES];
}
#pragma mark - 签到按钮点击事件
- (IBAction)signBtnClickAction:(id)sender {
    YLFaceIdentifyViewController *faceVC = [[YLFaceIdentifyViewController alloc] initWithNibName:@"YLFaceIdentifyViewController" bundle:nil];
    [self.navigationController pushViewController:faceVC animated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

extern NSString *kServerHttpBaseUrl;
- (void)requestWithMeetingNo{
    NSString *url = [NSString stringWithFormat:@"%@%@",kServerHttpBaseUrl,kCountMeetingUser_url];
    NSDictionary *params = @{@"meetNo":[CMBasicData getMerInfo].meetingNo?:@""};
    [HttpRequest requestWithURLString:url parameters:params type:HttpRequestTypePost success:^(id responseObject) {
        NSDictionary *dict = responseObject;
        YLHttpModel *httpModel = [YLHttpModel yy_modelWithDictionary:dict];
        if([httpModel.status isEqualToString:@"200"]){
            YLSignFirstModel *signModel = [YLSignFirstModel yy_modelWithDictionary:[dict objectForKey:@"data"]];
            self.attendanceLabel.text = [NSString stringWithFormat:@"%03d",[signModel.signedUserCount intValue]];
            self.SupposedComeLabel.text = [NSString stringWithFormat:@"%03d",[signModel.totalUserCount intValue]];
        }else{
            [KDAlertView alertWithMessage:httpModel.msg?:@""];
        }
        
    } failure:^(NSError *error) {
        [KDLoadFrame withState:KDLoadStateError];
    }];
}

@end
